package org.cbg.frame;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JInternalFrame;
import javax.swing.plaf.basic.BasicInternalFrameUI;

import com.gl.util.Delete;
import org.cbg.panel.TrslationTreasurepavilionJpanel;
import org.come.until.FormsManagement;
import org.come.until.MessagrFlagUntil;
import org.come.until.Music;
import org.come.until.Util;

import com.tool.tcpimg.UIUtils;

/**
 * 藏宝阁主面板
 * 
 * @author Administrator
 * 
 */

public class TrslationMainJframe extends JInternalFrame implements MouseListener {
    private TrslationTreasurepavilionJpanel trslationMainJpanel;
    private int first_x, first_y;// x、y坐标

    /**
     * 全局变量初始化：<br>
     * 1、确认打开那个窗口(0、首页最新上架页面 1、首页 2、大话币 3、道具 4、召唤兽 5、装备 6、灵宝 7、公示期 8、收藏
     * 9、我要卖之已寄售品)<br>
     * 2、获取点击收藏的按钮<br>
     * 3、消息勾选个数<br>
     * 4、当前页数消息总个数<br>
     * 5、我的藏宝阁之我的货物勾选个数<br>
     * 6、我的货物可勾选总个数<br>
     * 7、收藏的物品集合<br>
     */
    private int panelOpen = 0;
    private Object shoucangBtn;
    private int xiaoxiGouxuangeshu = 0;
    private int xiaoxiGeshuMax = 0;
    private int goodsGouxuangeshu = 0;
    private int goodsGeshuMax = 0;
    private List<BigDecimal> shoucangWupinList;

    /**
     * 实例化界面
     *
     * @return
     */
    public static TrslationMainJframe getTrslationMainJframe() {
        return (TrslationMainJframe) FormsManagement.getInternalForm(78).getFrame();
    }

    public TrslationMainJframe() {
        super();
        trslationMainJpanel = new TrslationTreasurepavilionJpanel();
        this.getContentPane().add(trslationMainJpanel);
        // this.setPreferredSize(new Dimension(636,537));
        this.setBorder(BorderFactory.createEmptyBorder());// 去除内部窗体的边框
        ((BasicInternalFrameUI) this.getUI()).setNorthPane(null);// 去除顶部的边框
        this.setBounds(200, 40, 800, 550);
        this.setVisible(false);
        this.setBackground(UIUtils.Color_BACK);
        // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // this.add(trslationMainJpanel);

        this.pack();

        this.addMouseMotionListener(new MouseMotionListener() {// 判断窗口移动的位置

            @Override
            public void mouseMoved(MouseEvent e) {
                if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE13)) {
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                }
            }

            @Override
            public void mouseDragged(MouseEvent e) {
                if (isVisible()) {
                    int x = e.getX() - first_x;
                    int y = e.getY() - first_y;
                    setBounds(x + getX(), y + getY(), getWidth(), getHeight());
                }
            }
        });
        this.addMouseListener(this);

    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {
        // 开启窗口音效
        Music.addyinxiao("关闭窗口.mp3");
        if (e.isMetaDown()) {// 检测鼠标右键单击
            // 关闭窗口音效
            // Music.addyinxiao("关闭窗口.mp3");
            FormsManagement.HideForm(78);
//            try {
//                Deciphering.Decipheringcbg();
//            } catch (IOException ioException) {
//                ioException.printStackTrace();
//            }
            //图片加密
//            Delete.Deletexcbg();

        } else {
            FormsManagement.Switchinglevel(78);

        }
        this.first_x = e.getX();
        this.first_y = e.getY();

    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    // TODO 藏宝阁前端时间显示
    /**
     * 判断时间是否在公示期还是在上架期
     *
     * @param upTime
     * @param number
     * @return
     */
    public static String remainingTime(Date upTime, Integer number) {

        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        calendar.setTime(upTime);
        calendar.add(Calendar.HOUR_OF_DAY, +number);// +1今天的时间加一天
        Date date = calendar.getTime();
        int compareTo = date.compareTo(new Date(Util.getTime2()));// 比较时间
        long timeChazhi = date.getTime() - Util.getTime2();
        long day = timeChazhi / (1000 * 60 * 60 * 24);
        long hour = (timeChazhi / (1000 * 60 * 60) - day * 24);
        long min = ((timeChazhi / (60 * 1000)) - day * 24 * 60 - hour * 60);
        // long s = (timeChazhi/1000 - day*24*60*60 - hour*60*60 - min*60);
        if (compareTo > 0 && number <= 1) {
            // 公示期剩余
//            return day + "天" + hour + "小时" + min + "分";
            return day + "天" + hour + "小时";
        } else if (compareTo <= 0) {
//        } else if (compareTo <= 0 && number <= 1) {
            return "已上架";
        } else {
            // 上架时间剩余
            long timeChazhi1 = date.getTime() - Util.getTime2();
            long day1 = timeChazhi1 / (1000 * 60 * 60 * 24);
            long hour1 = (timeChazhi1 / (1000 * 60 * 60) - day1 * 24);
            long min1 = ((timeChazhi1 / (60 * 1000)) - day1 * 24 * 60 - hour1 * 60);
//            return day1 + "天" + hour1 + "小时" + min1 + "分";
            return day1 + "天" + hour1 + "小时";
        }
    }

    public TrslationTreasurepavilionJpanel getTrslationMainJpanel() {
        return trslationMainJpanel;
    }

    public void setTrslationMainJpanel(TrslationTreasurepavilionJpanel trslationMainJpanel) {
        this.trslationMainJpanel = trslationMainJpanel;
    }

    public int getPanelOpen() {
        return panelOpen;
    }

    public void setPanelOpen(int panelOpen) {
        this.panelOpen = panelOpen;
    }

    public Object getShoucangBtn() {
        return shoucangBtn;
    }

    public void setShoucangBtn(Object shoucangBtn) {
        this.shoucangBtn = shoucangBtn;
    }

    public int getXiaoxiGouxuangeshu() {
        return xiaoxiGouxuangeshu;
    }

    public void setXiaoxiGouxuangeshu(int xiaoxiGouxuangeshu) {
        this.xiaoxiGouxuangeshu = xiaoxiGouxuangeshu;
    }

    public int getXiaoxiGeshuMax() {
        return xiaoxiGeshuMax;
    }

    public void setXiaoxiGeshuMax(int xiaoxiGeshuMax) {
        this.xiaoxiGeshuMax = xiaoxiGeshuMax;
    }

    public int getGoodsGouxuangeshu() {
        return goodsGouxuangeshu;
    }

    public void setGoodsGouxuangeshu(int goodsGouxuangeshu) {
        this.goodsGouxuangeshu = goodsGouxuangeshu;
    }

    public int getGoodsGeshuMax() {
        return goodsGeshuMax;
    }

    public void setGoodsGeshuMax(int goodsGeshuMax) {
        this.goodsGeshuMax = goodsGeshuMax;
    }

    public List<BigDecimal> getShoucangWupinList() {
        return shoucangWupinList;
    }

    public void setShoucangWupinList(List<BigDecimal> shoucangWupinList) {
        this.shoucangWupinList = shoucangWupinList;
    }

}
